#include "get_arg.h"


#include <boost/program_options/options_description.hpp>
#include <boost/program_options.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/lexical_cast.hpp>
// link with -lboost_filesystem-gcc -lboost_program_options-gcc
// program_options_helper.cpp


#include <iostream>
#include <string>
#include <set>
#include <cmath>




// my functions
#define DEBUG_LEVEL 6
#include <debug_func.h>
#include <ultoa.h>
#include <print_error.h>
#include <stdexcept>
#include <program_options_helper.h>

using std::string;
using std::cerr;
using std::ofstream;
using std::cerr;
using std::cout;
using boost::filesystem::path;
using boost::filesystem::extension;
using boost::filesystem::basename;
using boost::lexical_cast;


using namespace program_options_helper;
namespace po = boost::program_options_lg;

//_______________________________________________________________________________________

//		process_command_line_options

//				from command line
//				Created [9/13/2001]

//_______________________________________________________________________________________
bool process_command_line_options(int argc, char* argv[], t_program_args& args)
{

	args.optional_args.add_options()
	("output_path,o", po::value<string>(&args.output_path)
										->default_value("[PATH][FILENAME].full.nh")
										->set_name("PATH"),
									"Path for output files.\n");

	args.add_std_options();
	po::options_description all_args("");
	all_args
			.add(args.optional_args);

	// parse command line
	po::variables_map vm;
	po::store(po::command_line_parser(argc, argv).options(all_args).run(), vm);
	po::notify(vm);

	if (vm.count("version"))
	{
		print_version(cerr, *argv, "1.1\n"
			"\tHistory: \n\n"
			"\tv 1.0\1"
			"Initial version\n"
//			"\tv 1.1\1"
//			"Fixed nasty bug where top-most clusters were joined by zero length branches.\n"
			);
		return false;
	}
	if (vm.count("help"))
	{
		string exe_description =
			"Takes New Hampshire sub-trees via STDIN and joins them back to their "
			"originating tree with stubs by looking up the sub-tree name and the "
			"filenames.\n"
			"These should be separated by whitespace on the accession of each sub-tree\n"
			"The output files will be placed in the specified (--output-path) PATH with "
			"    [PATH] matching the path of the input file (including the last slash)\1"
			"    [FILENAME] matching the filename of the input file (sans path/extension)\1"
			"    [EXT] matching the extension of the input file (including the last dot)\n";

		print_usage(cerr, *argv, "< TREE_FILE",
									all_args, exe_description, 80);
		return false;
	}



	args.open_err_log();
	return true;
}
